<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymleaf.org/thymeleaf-extras-springsecurity5"
>
<head>
    <meta charset="UTF-8">
    <title th:text="${article.title}">Title</title>
</head>
<body>

<strong>
    <span sec:authentication="name"></span>
</strong>
<span sec:authorize="hasRole('ROLE_ADMIN')">管理员</span>
<span sec:authorize="hasRole('ROLE_USER')">普通用户</span>

<hr>

Thymeleaf -- th:text
<div th:text="${article.title}"></div>
<br>

Thymeleaf -- th:text
<div th:text="${article.body}"></div>
<br>

Thymeleaf -- th:object
<div th:object="${article}"></div>
<br>

Thymeleaf -- th:action
<form th:action="@{/article/}+${article.id}" method="post">

    Thymeleaf -- th:value <input type="text" th:value="${article.id}" name="id">
    <br>

    Thymeleaf -- th:field $ <input type="text" id="title1" name="title" th:field="${article.title}">
    <br>

    <!--    Thymeleaf &#45;&#45; th:field * <input type="text" id="title2" name="title" th:field="*{title}">  -->
</form>
<br>

Thymeleaf 中的 url 处理
<a th:href="@{http://www.baidu.com}">绝对路径</a>
<a th:href="@{/}">相对路径</a>
<a th:href="@{css/bootstrap.min.css}">默认访问 static 下的文件夹</a>
<br/>

Thymeleaf 进行条件求值 -- th:if 和 th:unless
<br>
<a th:href="@{/login}" th:if="${session.user == null}">Login</a>
<a th:href="@{/login}" th:unless="${session.user == 'admin'}">Logout</a>

<br>
Thymeleaf 的 switch

<div th:switch="${article.title}">
    <p th:case="admin">管理员（这个 case 还不让有中文汉字）</p>
    <p th:case="guess">游客</p>
    <p th:case="*">其他</p>
</div>

<br>

Thymeleaf 的字符串拼接替换
<div>
    <span th:text="hello + ${article.title}"></span>
</div>

<br>

Thymeleaf 的运算符
<div>
    <span th:text="1+1">1+1</span>
    <br>
    <div th:if="5 ge 4"> 3 &ge; 4</div>
    <!--  gt 大于； ge 大于等于； eq 等于； lt 小于； le 小于等于； ne 不等于  -->

</div>

Thymeleaf 的公用对象

<div>
    <span th:text="${#dates.format('2021-01-13 21:20:46', 'yyyy-MM-dd HH:mm:ss')}">格式化时间</span>
    <span th:if="${#strings.isEmpty(artcle.title)}">空</span>
</div>

Thymeleaf 处理循环遍历

<div>
    <div th:each="article:${articles}">
        <li th:text="${article.title}">文章标题</li>
        <li th:text="${article.body}">文章内容</li>
    </div>
</div>


</body>
</html>